package com.hnx.admin.security.filter;


import com.hnx.admin.security.api.JwtFilter;
import com.hnx.admin.security.core.SecurityProperties;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;
import java.util.Arrays;

/*
创建人： 倔强的头发
创建时间：2025/5/16
功能描述:

*/
@Component
@RequiredArgsConstructor
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
    private final JwtFilter jwtFilter;
    private final SecurityProperties securityProperties;
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
            throws ServletException, IOException {

        if(!Arrays.stream(securityProperties.getOpenApi()).anyMatch(n->n.equals(request.getRequestURI()))) {
            jwtFilter.match(request);
        }
        chain.doFilter(request, response);
    }
}
